
#include "Account.h"
#include <iostream>

using namespace npState;


//other constructors
Account::Account(const string& owner, double initBalance) // : BaseClass()
{
    this->state = nullptr;
    this->owner = owner;
    this->balance = initBalance;

    cout << this->owner << "开户，初始金额为" << this->balance << endl;
    cout << "-----------------------------------------" << endl;
}

//public methods
void Account::deposit(double amount) throw(ErrorEnum)
{
    if (!this->state)
    {
        throw ErrorEnum::StateIsNull;
    }
    
    this->state->deposit(amount);

    cout << this->owner << "存款" << endl;
    cout << "现在账户余额为" << this->balance << endl;
    cout << "现在账户状态为" << this->state->toString() << endl;
    cout << "-----------------------------------------------" << endl;
}

void Account::withdraw(double amount) throw(ErrorEnum)
{
    if (!this->state)
    {
        throw ErrorEnum::StateIsNull;
    }
    
    this->state->withdraw(amount);

    cout << this->owner << "取款" << endl;
    cout << "现在账户余额为" << this->balance << endl;
    cout << "现在账户状态为" << this->state->toString() << endl;
    cout << "-------------------------------------" << endl;
}

void Account::calcInterest() throw(ErrorEnum)
{
    if (!this->state)
    {
        throw ErrorEnum::StateIsNull;
    }
    
    this->state->calcInterest();
}

//protected methods

//private methods

//static part

//others
